<%@taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>
<%@taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<%@taglib uri="http://java.fckeditor.net" prefix="FCK" %>

<div>
    <logic:present name="acc">
        <p align="right">
            <a href="AdminCar.do?action=listCar" >Car manager</a>&emsp;&emsp;&emsp;
                <a href="AdminCar.do?action=listCarModel" >Model manager</a> &emsp;&emsp;&emsp;
                <a href="AdminCar.do?action=listCarType">Type manager</a>
        </p>
        <form name="fr" action="AdminCar.do" method="post" >
            <table width="100%" align="center">
                <tbody>
                    <tr>
                        <td>
                            <table class="tablemain" border="0">
                                <tr >
                                    <th height="32" colspan="3" scope="col">Manager Car </th>
                                </tr>
                                <tr>
                                    <td height="39"><div align="right">CarId : </div></td>
                                    <td colspan="2"><input type="text" readonly name="carId" id="id" value="${carDTO.detailDTO.carId}" /></td>
                                </tr>
                                <tr>
                                    <td height="39"><div align="right">CarName : </div></td>
                                    <td colspan="2"><input type="text" name="carName" id="name" value="${carDTO.carName}" /></td>
                                </tr>
                                <tr>
                                    <td height="39"><div align="right">Details : </div></td>
                                    <td colspan="2">
                                        <FCK:editor instanceName="detail" value="${carDTO.detail}"   width="100%" height="200">

                                        </FCK:editor>
                                    </td>
                                </tr>
                                <tr>
                                    <td height="39"><div align="right">Model name : </div></td>
                                    <td colspan="2">
                                        <select name="model">
                                            <logic:present name="listModel">
                                                <logic:iterate name="listModel" id="listModel">
                                                    <option value="<bean:write name="listModel" property="modelId"/>">
                                                        <bean:write name="listModel" property="modelName"/>
                                                    </option>
                                                </logic:iterate>
                                            </logic:present>
                                        </select>
                                    </td>
                                </tr>
                                <tr>
                                    <td height="39"><div align="right">Type name : </div></td>
                                    <td colspan="2">
                                        <select name="type">
                                            <logic:present name="listType">
                                                <logic:iterate name="listType" id="listType">
                                                    <option value="<bean:write name="listType" property="typeId"/>">
                                                        <bean:write name="listType" property="typeName"/>
                                                    </option>
                                                </logic:iterate>
                                            </logic:present>
                                        </select>
                                    </td>
                                </tr>
                                <tr>
                                    <td height="39"><div align="right">AirConditional : </div></td>
                                    <td colspan="2">
                                        <select name="air">
                                            <option value="1">Yes</option>
                                            <option value="0">No</option>
                                        </select></td>
                                </tr>
                                <tr>
                                    <td height="39"><div align="right">Quantity: </div></td>
                                    <td colspan="2"><input type="text" name="quantity" id="qty" value="${carDTO.quantity}"  /></td>
                                </tr>
                                <tr>
                                    <td height="39"><div align="right">SeatQty: </div></td>
                                    <td colspan="2"><input type="text" name="seatQty" id="seat" value="${carDTO.seatQty}"  /></td>
                                </tr>
                                <tr>
                                    <td height="39"><div align="right">Price : </div></td>
                                    <td colspan="2"><input type="text" name="price" id="price" value="${carDTO.price}"/></td>
                                </tr>

                                <tr>
                                    <td height="39" colspan="3"><div align="center">
                                            <input type="submit" name="action" value="UpdateCar" onclick="return formValidator()" />
                                        </div></td>
                                </tr>

                            </table>
                        </td>
                    </tr>
                </tbody>
            </table>
        </form>
    </logic:present>
    <logic:notPresent name="acc">
        <jsp:forward page="adminHome.jsp"/>
    </logic:notPresent>
</div>
<script>
    function addnew(){
        document.getElementById("image").innerHTML += "<input name='images' type='file' id='img'> <br/>";
    }
    //check image
    function checkimg(element,helperMsg){
        if(element.value == "No file chosen"){
            alert(helperMsg);
            elem.focus(); // set the focus to this input
            return false;
        }
        return true;
    }
    // If the length of the element's string is 0 then display helper message
    function notEmpty(elem, helperMsg){
        if(elem.value.length == 0){
            alert(helperMsg);
            elem.focus(); // set the focus to this input
            return false;
        }
        return true;
    }
    // If the element's string matches the regular expression it is all numbers
    function isNumeric(elem, helperMsg){
        var numericExpression = /^[0-9]+$/;
        if(elem.value.match(numericExpression)){
            return true;
        }else{
            alert(helperMsg);
            elem.focus();
            return false;
        }
    }
    function formValidator(){
        // Make quick references to our fields
        var carName = document.getElementById('name');
        var qty = document.getElementById('qty');
        var seat = document.getElementById('seat');
        var price = document.getElementById('price');

        // Check each input in the order that it appears in the form!
        if(notEmpty(carName, "Please enter car name")){
            if(notEmpty(qty, "Please enter quantity")){
                if(isNumeric(qty, "Quantity is number")){
                    if(notEmpty(seat, "Please enter seat quantity")){
                        if(isNumeric(seat,"seat quantity is number")){
                            if(notEmpty(price, "Please enter price")){
                                if(isNumeric(price,"price is number")){
                                    return true;
                                }

                            }
                        }
                    }
                }
            }
        }
     
        return false;
    }
</script>